package com.example.myapplication;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by lyt on 2020/12/5 0005.
 */

public class MyDatabaseHelper extends SQLiteOpenHelper {
    private static final String name = "memo.db";//数据库名称
    private static final int version = 1;//数据库版本

    private Context mContext;

    public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
        super(context,name,factory,version);
        mContext = context;
    }

    @Override
    //创建数据库
    public void onCreate(SQLiteDatabase db) {
//        db.execSQL(CREATE_MEMO_User);
        db.execSQL("CREATE TABLE IF NOT EXISTS User (username varchar primary key, password varchar(60))");
        db.execSQL("CREATE TABLE IF NOT EXISTS MemoContent (title varchar primary key, content varchar)");
        Toast.makeText(mContext,"Create succeeded",Toast.LENGTH_LONG).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists User");
        db.execSQL("drop table if exists MemoContent");
        onCreate(db);
    }


}
